//
//  CN_MacroThread.swift
//  Voice
//
//  Created by 卢逢卫 on 2024/3/5.
//

import UIKit

public struct Macro_Thread {
    public static var shared = Macro_Thread()

    /// 线程组
    public func requestWorkingGroup(label: String = "request_many_queue", vc: UIViewController, groups: [Selector], complete: (() -> Void)?) {
        let workingGroup = DispatchGroup()
        let workingQueue = DispatchQueue(label: label)
        
        for selector in groups {
            workingGroup.enter()
            workingQueue.async {
                autoreleasepool {
                    vc.perform(selector)
                    workingGroup.leave()
                }
            }
        }
        
        workingGroup.notify(queue: .main) {
            complete?()
        }
    }
}
